<!DOCTYPE html>
<html lang="en">
<head>
 <meta charset="UTF-8">
 <title>登陆账号</title>
 <link rel="stylesheet" href="static/css/common_form.css">
</head>
<body ng-app="loginApp">
 <header>
 <div class="header-line"></div>
 </header>
 <div class="content">
 <img class="content-logo" src="static/image/form_logo.jpg" alt="logo">
 <h1 class="content-title">登录</h1>
 <div class="content-form">
  <form method="post" action="" name="loginForm" ng-controller="login">
  <div id="change_margin_1">
   <input class="user" spellcheck="false"  type="text" name="username" placeholder="请输入用户名" ng-model="formData.username" ng-minlength="6" ng-maxlenth="16" required/>
  </div>
  <!-- input的value为空时弹出提醒 -->
  <p id="remind_1">
<span style="color:red" ng-show="loginForm.username.$invalid">
   <span ng-show="loginForm.username.$error.minlength">
         *用户名不得少于6位
   </span>
   <span ng-show="loginForm.username.$error.maxlenth">
        *用户名不得超过16位
   </span>
</span>
</p>
  <div id="change_margin_2">
   <input class="password" type="password" name="password" placeholder="请输入密码" ng-model="formData.password" ng-minlength="6" ng-maxlength="16" required/>
  </div>
  <!-- input的value为空时弹出提醒 -->
  <p id="remind_2">
    <span style="color:red" ng-show="loginForm.password.$invalid">
   <span ng-show="loginForm.password.$error.minlength">
	 *密码不得少于6位
	  </span>
      <span style="color:red" ng-show="loginForm.password.$error.maxlength">
      密码不得超过16位
     </span>
	</span>
 </p>
  <div id="change_margin_3">
   <input class="content-form-signup" type="button" value="登录" ng-controller="login" ng-click="asave()"  ng-disabled="loginForm.username.$invalid || loginForm.password.$invalid"/>
  </div>
  </form>
 </div>
 <div class="content-login-description">没有账户？</div>
 <div><a class="content-login-link" href="/register">注册</a></div>
 </div>
<script src="static/js/jquery-2.1.1.min.js"></script>
<script src="static/js/aj.js"></script>
<script src="static/layer-2.4/layer.js"></script>
<script type="text/javascript">
var app = angular.module('loginApp',[]);
    app.config(['$interpolateProvider', function($interpolateProvider) {
    $interpolateProvider.startSymbol('[[');
    $interpolateProvider.endSymbol(']]');
}]);
app.controller('login',['$scope',function($scope){

}]);
  var login = app.controller('login',['$scope','$http',function($scope,$http){
     $scope.asave= function(){
         $http({
             method: 'POST',
             url: '/login',
             data: $.param($scope.formData), // pass in data as strings
             headers: {'Content-Type':'application/x-www-form-urlencoded; charset=UTF-8'}  
         }).success(function (data) {
           if(data.errorNumber==0x01){
            layer.alert('用户名不存在', {icon: 5});
            //layer.alert("用户名不存在");
          }else if(data.errorNumber==0x02){
             layer.alert('密码不正确', {icon: 2});
          }else if(data.errorNumber==0x17){
             // layer.alert('用户已登录', {icon: 5});
             layer.msg('用户已登录', {
               offset: 0,
               shift: 6
});
           }else{  
         ////加载层-风格4
       layer.msg('登录中', {icon: 16});
        url="/chat?username=" + data.info;
        setTimeout(function(){
       layer.closeAll('loading');
            }, 3000);
            //layer.alert('登录成功', {icon: 6});
             location.href = url;
           }
		
          });
 
     };
 }]);
</script>
</body>
</html> 

